package public

import (
	"github.com/gin-gonic/gin"
	"go-interview-forum/resp"
	"go-interview-forum/service/public"
	"log"
)

func UploadImage(c *gin.Context) {
	fileInfo, err := c.FormFile("image")
	if err != nil {
		log.Println(err)
		resp.QueryErrorResp(c, "请上传图片")
		return
	}

	path, err := public.UploadImage(fileInfo)
	if err != nil {
		resp.ServerErrorResp(c, resp.QUERY_ERR, err.Error())
		return
	}

	resp.SuccessResp(c, path)
}
